#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div id="datagridId"></div>

        <div id="datagridTb">
            <div class="row">
                <div class="col-md-12">
                    <form id="searchForm">
                        <div class="easyui-panel" title="信息查询" style="width:100%;padding:10px;"
                             data-options="iconCls:'icon-application_form'">

                            #(_res.get('auth.form.username')): <input class="easyui-textbox" id="custNo"
                                                                      style="width:200px">&nbsp;&nbsp;
                            #(_res.get('auth.form.aaid')): <input class="easyui-textbox" id="aaid" style="width:200px">&nbsp;&nbsp;
                            #(_res.get('user.form.phone')): <input class="easyui-textbox" id="phoneNum"
                                                                   style="width:200px">&nbsp;&nbsp;
                            厂商: <input class="easyui-textbox" id="deviceType" style="width:200px">&nbsp;&nbsp;
                            系统类型: <input class="easyui-textbox" id="osType" style="width:200px">&nbsp;&nbsp;
                            开始时间: <input class="easyui-datebox" id="startTime" data-options="editable:false" style="width:200px">&nbsp;&nbsp;
                            结束时间: <input class="easyui-datebox" id="endTime" data-options="editable:false" style="width:200px">&nbsp;&nbsp;
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="datagridQuery();" iconCls="icon-zoom">#(_res.get('system.common.search'))</a>
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="$('#searchForm').form('clear');" iconCls="icon-zoom_out">#(_res.get('system.common.clear'))</a>
                            #if(certManageflag == "1")
                                <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                                   onclick="certFrozen();" iconCls="icon-shape_rotate_clockwise">冻结</a>
                                <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                                   onclick="certThaw();" iconCls="icon-shape_rotate_clockwise">解冻</a>
                                <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                                   onclick="certCancel();" iconCls="icon-shape_rotate_clockwise">注销</a>
                            #end
                        </div>
                    </form>
                </div>
                <div class="row">
                    <div class="col-md-12" style="padding: 5px 25px;">
                        #for(resource : resourceList)
                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'#(resource.icon)',plain:true" id='#(resource.url)'>#(_res.get(resource.resourceName))</a>
                        #end
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>

#end


#define css()

#end


#define js()

<script type="text/javascript">
    var _datagrid = "datagridId", _form = "formId", _datagridTb = "datagridTb";
    var datagridListUrl = contextRootPath + '/authenticators/list';

    $(function () {

        //初始化表格
        $("#" + _datagrid).datagrid({
            url: datagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 20,
            toolbar: '#' + _datagridTb,
            singleSelect: false,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            onLoadSuccess: function (data) {
                if (data.total === 30000) {
                    $(".pagination-info").prepend("<span style='color:red;margin-right:15px;'>查询结果大约30000条,请缩小查询范围</span>");
                }
            },
            columns: [[
                {
                    field: DBConts.TABLE_AUTHENTICATORS.AUTH_ID,
                    title: DBConts.TABLE_AUTHENTICATORS.AUTH_ID,
                    checkbox: true
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.CUST_NO,
                    title: "#(_res.get('auth.form.username'))"
                },


                {
                    field: DBConts.TABLE_AUTHENTICATORS.STATUS,
                    title: "#(_res.get('auth.form.status'))",
                    formatter: function (value, row, index) {

                        var status = row.status;
                        var result;
                        if (status === 1) {
                            result = "<span>#(_res.get('auth.form.reg'))</span>";
                        } else {
                            result = "<span>#(_res.get('auth.from.log'))</span>";
                        }
                        return result;
                    }
                },
                {
                    field: "cert_status",
                    title: "证书状态",
                    formatter: function (value, row, index) {

                        var status = row.cert_status;
                        var result;
                        if (status === 1) {
                            result = "<span>已签发待安装</span>";
                        } else if (status === 2) {
                            result = "<span>已安装待激活</span>";
                        }else if (status === 3) {
                            result = "<span>已经激活</span>";
                        }else if (status === 4) {
                            result = "<span>已注销</span>";
                        }else if (status === 5) {
                            result = "<span>已冻结</span>";
                        }else {
                            result = "<span>无</span>";
                        }
                        return result;
                    }
                },
                {
                    field: "is_root",
                    title: "设备是否root",
                    formatter: function (value, row, index) {

                        var status = row.is_root;
                        var result;
                        if (status === 'true') {
                            result = "<span>是</span>";
                        } else {
                            result = "<span>否</span>";
                        }
                        return result;
                    }
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.TENANT_ID,
                    title: "#(_res.get('auth.form.tenant'))"
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.AUTH_TYPE,
                    title: "#(_res.get('policy.form.authtype'))",
                    formatter: function (value, row, index) {
                        return getAuthType(row.auth_type);
                    }
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.TRANS_TYPE,
                    title: "#(_res.get('policy.form.transtype'))",
                    formatter: function (value, row, index) {
                        return getTransType(row.trans_type);
                    }
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.MOBILE,
                    title: "#(_res.get('user.form.phone'))"
                },
                {
                    field: DBConts.TABLE_DEVICES.DEVICE_NAME,
                    title: '设备型号/版本号'
                },
                {
                    field: DBConts.TABLE_DEVICES.OS_VERSION,
                    title: '系统版本'
                },
                {
                    field: DBConts.TABLE_DEVICES.OS_TYPE,
                    title: '系统类型'
                },
                {
                    field: DBConts.TABLE_DEVICES.DEVICE_TYPE,
                    title: '厂商/浏览器'
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.KEYID,
                    title: "#(_res.get('auth.form.keyid'))"
                },
                {
                    field: DBConts.TABLE_DEVICES.DEVICE_ID,
                    title: '设备标识'
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.AAID,
                    title: "#(_res.get('auth.form.aaid'))"
                },
                {
                    field: 'createts',
                    title: "#(_res.get('phone.form.creates'))"
                }
            ]]
        });
    });


    function datagridQuery() {
        var flag = $("#searchForm").form('enableValidation').form('validate');

        if (!flag) return;

        $("#" + _datagrid).datagrid({
            queryParams: {
                'authenticators.cust_no': $('#custNo').val(),
                'authenticators.aaid': $('#aaid').val(),
                'authenticators.mobile': $('#phoneNum').val(),
                'device_type': $('#deviceType').val(),
                'os_type': $('#osType').val(),
                'authenticators.tenant_id':$('#tenantId').val(),
                'start_time':$('#startTime').val(),
                'end_time':$('#endTime').val()
            }
        });
    }
    
    function certFrozen() {
        var selections = $('#' + _datagrid).datagrid('getSelections');
        var ids = "";

        if (selections.length < 1) {
            $.messager.alert("提示框", "请选择需要操作的数据!", "warning");
            return;
        }

        if (selections.length > 1) {
            $.messager.alert("提示框", "请选择一个需要操作的数据!", "warning");
            return;
        }

        $.each(selections, function (i, v) {
            ids += v[DBConts.TABLE_AUTHENTICATORS.AUTH_ID];
        });
        console.log("ids:"+ids);

        var params={"ids":ids};

        $.ajax({
            type: 'post',
            url: contextRootPath + "/authenticators/certFrozen",
            data:params,
            async: false,
            dataType: 'json',
            success: function (data) {
                var params = {};
                params.element = _datagrid;
                params.data = data;
                resultCallback(params);
            }
        });
    }
    function certThaw() {
        var selections = $('#' + _datagrid).datagrid('getSelections');
        var ids = "";

        if (selections.length < 1) {
            $.messager.alert("提示框", "请选择需要操作的数据!", "warning");
            return;
        }

        if (selections.length > 1) {
            $.messager.alert("提示框", "请选择一个需要操作的数据!", "warning");
            return;
        }

        $.each(selections, function (i, v) {
            ids += v[DBConts.TABLE_AUTHENTICATORS.AUTH_ID];
        });
        console.log("ids:"+ids);

        var params={"ids":ids};

        $.ajax({
            type: 'post',
            url: contextRootPath + "/authenticators/certThaw",
            data:params,
            async: false,
            dataType: 'json',
            success: function (data) {
                var params = {};
                params.element = _datagrid;
                params.data = data;
                resultCallback(params);
            }
        });
    }

    function certCancel() {
        var selections = $('#' + _datagrid).datagrid('getSelections');
        var ids = "";

        if (selections.length < 1) {
            $.messager.alert("提示框", "请选择需要操作的数据!", "warning");
            return;
        }

        if (selections.length > 1) {
            $.messager.alert("提示框", "请选择一个需要操作的数据!", "warning");
            return;
        }

        $.each(selections, function (i, v) {
            ids += v[DBConts.TABLE_AUTHENTICATORS.AUTH_ID];
        });
        console.log("ids:"+ids);

        var params={"ids":ids};

        $.ajax({
            type: 'post',
            url: contextRootPath + "/authenticators/certCancel",
            data:params,
            async: false,
            dataType: 'json',
            success: function (data) {
                var params = {};
                params.element = _datagrid;
                params.data = data;
                resultCallback(params);
            }
        });
    }
</script>
#end



